﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_MaterialPriceController : BaseApiController
    {
        #region DI

        public PB_MaterialPriceController(IPB_MaterialPriceBusiness pB_MaterialPriceBus)
        {
            _pB_MaterialPriceBus = pB_MaterialPriceBus;
        }

        IPB_MaterialPriceBusiness _pB_MaterialPriceBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_MaterialPrice>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_MaterialPriceBus.GetDataListAsync(input);
        }
        [HttpPost]
        ///返回Dto
        public async Task<PageResult<PB_MaterialPriceDTO>> GetDataListDto(PageInput<ConditionDTO> input)
        {
            return await _pB_MaterialPriceBus.GetDataListDTOAsync(input);
        }
        [HttpPost]
        public async Task<PB_MaterialPrice> GetTheData(IdInputDTO input)
        {
            return await _pB_MaterialPriceBus.GetTheDataAsync(input.id);
        }

        /// <summary>
        /// 保存计件单价
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveMaterialPrice(MaterialPriceDTO data)
        {
            await _pB_MaterialPriceBus.SaveMaterialPriceAsync(data);
        }

        /// <summary>
        /// 调整计件单价
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task UpdateMaterialPrice(MaterialPriceDTO data)
        {
            await _pB_MaterialPriceBus.UpdateMaterialPriceAsync(data);
        }

        /// <summary>
        /// 调整物料单价
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task UpdateLabourPrice(MaterialPriceDTO data)
        {
            await _pB_MaterialPriceBus.UpdateLabourPriceAsync(data);
        }

        /// <summary>
        /// 查询物料计件单价
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<PageResult<MaterialPriceListDTO>> GetMaterialPriceList(PageInput<MaterialPriceConditionDTO> input)
        {
            return await _pB_MaterialPriceBus.GetMaterialPriceListAsync(input);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_MaterialPrice data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_MaterialPriceBus.AddDataAsync(data);
            }
            else
            {
                await _pB_MaterialPriceBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_MaterialPriceBus.DeleteDataAsync(ids);
        }

        #endregion

    }
}